import json
import os

list={}
with open("ocr-exercise/val.json",'r',encoding='UTF-8') as f:
    load_dict=json.load(f)
    for x in load_dict:
        string=load_dict[x]
        i=0
        for y in string:
            list['{}_{}.jpg'.format(x.split('.')[0], i)]=y 
            i+=1


with open("character_val.json","w",encoding = 'utf-8') as file:
    json.dump(list,file,ensure_ascii=False,indent=4)

with open("character_val.json","r",encoding = 'utf-8') as f2:
    print(json.load(f2))

